package jmetal.metaheuristics.moead;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import jmetal.core.Problem;
import jmetal.core.Solution;
import jmetal.core.SolutionSet;
import jmetal.util.JMException;

public class MOEADUtils {

	public static Problem redefiendProblem(SolutionSet population, Problem problem, int cycle)
			throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException, JMException {
		Class<?> clazz = problem.getClass();
		Constructor<?> constr = clazz.getConstructor(Integer.class, Integer.class);
		problem = (Problem) constr.newInstance(problem.getNumberOfVariables(), cycle);
		for (int i = 0; i < population.size(); i++) {
			// 重新评估
			Solution solution = population.get(i);
			Solution newSolution = new Solution(solution, problem.getNumberOfObjectives());
			problem.evaluate(newSolution);
			population.set(i, newSolution);
		}
		return problem;
	}

}
